package xxdsqljob

class JobCfg {

    String jobName //job名称
    Date initTime //时间字符串
    Date startTime //最近一次执行完成时间
    Date lastTime //最近一次执行完成时间
    long period //时间间隔
    String unit //单位
    String active = "N" //状态：未激活、激活:N:Y
    String state = "NORMAL" // 运行状态:运行中RUN、正常NORMAL、异常ERROR
    String stateInfo //执行信息
    String uploadPath //上传路径

    String creator ;//操作人
    String updater;//最近一次更新人
    Date dateCreated;
    Date lastUpdated;

    static constraints = {
        jobName(nullable: false, blank: false, unique: true)
        initTime(nullable: false)
        period(nullable: false, blank: false)
        unit(nullable: false, blank: false)
        active(nullable: false, blank: false)
        state(nullable: false )
        stateInfo(nullable: true ,size:0..1000)
        uploadPath(nullable: true )
        lastTime(nullable: true )
        startTime(nullable: true)
        creator(nullable: true )
        updater(nullable: true )
    }
    static mapping = {
        version  false
    }

    public void logJobHis(){
        try{
            JobHis jobHis = JobHis.newInstance()
            jobHis.setProperty("jobName",this.jobName)
            jobHis.setProperty("initTime",this.initTime)
            jobHis.setProperty("startTime",this.startTime)
            jobHis.setProperty("lastTime",this.lastTime)
            jobHis.setProperty("period",this.period)
            jobHis.setProperty("unit",this.unit)
            jobHis.setProperty("active",this.active)
            jobHis.setProperty("state",this.state)
            jobHis.setProperty("stateInfo",this.stateInfo)
            jobHis.setProperty("uploadPath",this.uploadPath)
            jobHis.setProperty("creator",this.creator)
            jobHis.setProperty("updater",this.updater)
            jobHis.save()
        }catch (Exception e){
            println "JOB:${this.jobName} 记录日志异常........."
            e.printStackTrace()
        }
    }
}
